<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript" src="houtai/js/myjs.js"></script>
<script type="text/javascript">
var xmlhttp;
function checkloginname(){
	
	var loginname=document.getElementById("useLoginName").value;
	var id=document.getElementById("idid").value;

	if(loginname==""){
		document.getElementById("spnloginname").innerHTML="登录名不能为空";
		document.getElementById("spnloginname").style.color="red";
		return false;
	}
	document.getElementById("spnloginname").innerHTML="";
	xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=chloginname;

	xmlhttp.open("get","UserServlet?param=ajaxloginname&id="+id+"&loginname="+loginname+"&time="+new Date().getTime(), true);

	xmlhttp.send(null);
}

function chloginname(){
	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		var txt=xmlhttp.responseText;
		document.getElementById("spnloginname").innerHTML=txt;
		if(txt=="√"){
			document.getElementById("spnloginname").style.color="green";
		}else{
			document.getElementById("spnloginname").style.color="red";

		}
	}
	
}
function checklogname(){
var loginname=document.getElementById("useLoginName").value;
	
	if(loginname==""){
	document.getElementById("spnloginname").innerHTML="登录名不能为空";
	document.getElementById("spnloginname").style.color="red";
		return false;
	}else if(document.getElementById("spnloginname").innerHTML=="对不起！该用户名已被占用！"){
		return false;
	}
	document.getElementById("spnloginname").innerHTML="";
	return true;
}
function checkname(){
	if(document.getElementById("useName").value==""){
		document.getElementById("s2").innerHTML="姓名不能为空";
		document.getElementById("s2").style.color="red";
		return false;
	}
	document.getElementById("s2").innerHTML="";
	return true;
}

function checkaddress(){
	if(document.getElementById("useAddress").value==""){
		document.getElementById("s3").innerHTML="地址不能为空";
		document.getElementById("s3").style.color="red";
		return false;
	}
	document.getElementById("s3").innerHTML="";
	return true;
}
function checkidcard(){
	var idcard=document.getElementById("useIdCard").value;
	if(idcard==""){
		document.getElementById("s4").innerHTML="身份证不能为空";
		document.getElementById("s4").style.color="red";
		return false;
	}
	
	var card=/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2016)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/;                          
	if(!card.test(idcard)){
		document.getElementById("s4").innerHTML="请输入正确的身份证号";
		document.getElementById("s4").style.color="red";
		return false;
	}
	document.getElementById("s4").innerHTML="";
//	alert(idcard.charAt(16)%2);
	if(idcard.charAt(16)%2==0){
		document.getElementById("usesex1").checked=true;
	}else{
		document.getElementById("usesex2").checked=true;
	}
	return true;
}

function checakPhone(){
	var phone=document.getElementById("usePhone").value;
	if(phone==""){
		document.getElementById("s5").innerHTML="手机号不能为空";
		document.getElementById("s5").style.color="red";
		return false;
	}
	var tel= /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|17[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
	if(!tel.test(phone)){
		document.getElementById("s5").innerHTML="对不起！请输入正确的手机号！";
		document.getElementById("s5").style.color="red";
		
		return false;
	}
	document.getElementById("s5").innerHTML="";
	return true;
}

function checkemail(){
	var email=document.getElementById("useEmail").value;
	if(email==""){
		document.getElementById("s6").innerHTML="邮箱不能为空";
		document.getElementById("s6").style.color="red";
		return false;
	}
	var ema=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(!ema.test(email)){
		document.getElementById("s6").innerHTML="对不起！请输入正确的邮箱！";
		document.getElementById("s6").style.color="red";
		
		return false;
	}
	document.getElementById("s6").innerHTML="";
	return true;
}

function checkUser(){
	if(checkemail()&&checakPhone()&&checkidcard()&& checkaddress()&&checkname()&&checklogname()){
		if(confirm('是否确认提交？')){
         	document.getElementById("form1").submit();
         	return true;
         }else {
         	return false;
         }
	}else{
		return false;
	}

}




</script>

</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td style="height:25px; background-color:#f3f3f3; font-weight:bold" valign="top">
    &nbsp;&nbsp;&nbsp;&nbsp;当前位置：
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda个人信息管理</td>
  </tr>
  <tr>
    <td style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20" height="34"><img src="houtai/images/main_headerL.gif" width="20" height="34"></td>
          <td style="color:#90c8e8;"><img src="houtai/images/icon_card.gif" width="16" height="16" align="absmiddle">&nbsp;&nbsp;<strong>修改用户信息</strong></td>
          <td align="right" class="white" style="padding-right:20px">
          <a href="javascript:history.go(-1);" class="barBtn" ><img src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a>
          <a href="javascript:history.go(+1);" class="barBtn" ><img src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a>
          <a href="javascript:document.location.reload();" class="barBtn"><img src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="100%" valign="top">
    <div style="overflow:auto;height:100%; width:100%">
    <form id="form1" action="<%=request.getContextPath() %>/UserServlet?param=edit" method="post">
      <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
        <TR>
       		<input type="hidden" id="idid" value="${sessionScope.user.useId }">
          <th width="20%" align="center">用户登录名</th>
          <TD class="BGCgray"><input type="text" name="useLoginName" id="useLoginName"  onblur="checkloginname()" value="${sessionScope.user.useLoginName  }"/><span id="spnloginname" style="color: green">√</span></TD>
          </TR>
        <TR>
          <th align="center"><span class="BGCgray">真实姓名</span></th>
          <TD class="BGCgray"><input name="useName" type="text" id="useName" onblur="checkname()" value="${sessionScope.user.useName }"/><span id="s2" style="color: green">√</span></TD>
        </TR>
		<TR>
          <th align="center">身份证号</th>
          <TD class="BGCgray"><input name="useIdCard" type="text" id="useIdCard" onblur="checkidcard()" value="${sessionScope.user.useIdCard }"/><span id="s4"></span></TD>
        </TR>
        <TR>
          <th align="center">性别</th>
          <TD class="BGCgray"> 
          <input type="radio" name="useSex" id="usesex2" value="1"  ${sessionScope.user.useSex==1?"checked='checked'":"" }  />男<input type="radio" name="useSex" id="usesex1" value="0"    ${sessionScope.user.useSex==0?"checked='checked'":"" }/>女
          </TD>
        </TR>
        <TR>
          <th align="center">联系电话</th>
          <TD class="BGCgray"><input name="usePhone" type="text" id="usePhone" onblur="checakPhone()" value="${sessionScope.user.usePhone }"/><span id="s5" style="color: green">√</span></TD>
        </TR>
        <TR>
          <th align="center">地址</th> 
          <TD class="BGCgray"><input name="useAddress" type="text" id="useAddress" onblur="checkaddress()" value="${sessionScope.user.useAddress }"/><span id="s3" style="color: green">√</span></TD>
        </TR>
        <TR>
          <th align="center">邮箱</th>
          <TD class="BGCgray"><input name="useEmail" type="text" id="useEmail" onblur="checkemail()" value="${sessionScope.user.useEmail }"><span id="s6" style="color: green">√</span></TD>
        </TR>
        
      </table>
      </form>
      <div style="width:100%; text-align:center; padding:5px">
        <BUTTON style="HEIGHT:25px" onclick ="return checkUser();"><img src="houtai/images/btn_edit.gif" width="16" height="16" align="absmiddle"> 保存</BUTTON>
        <BUTTON style="HEIGHT:25px" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回</BUTTON>
      </div>
      
    </div>
  </td>
  </tr>
</table>
</body>
</html>